package com.yjha.ai.demos.web.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.ai.zhipuai.ZhiPuAiChatOptions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.HashSet;
import java.util.Set;

@RestController
@RequestMapping("/ai")
public class FunctionCallController {

    @Resource
    private ZhiPuAiChatModel chatModel;

    @GetMapping(value = "/call" )
    public String generate(@RequestParam(value = "message", defaultValue = "查看兰州市张三的详细信息") String message) {

        //存放 function 函数
        Set<String> functions = new HashSet<>();
        functions.add("addressUserFunction");

        //配置
        ZhiPuAiChatOptions chatOptions = ZhiPuAiChatOptions.builder()
                .withFunctions(functions)
                .withModel("glm-4-airx")
                .build();

        //执行请求
        return chatModel.call(new Prompt(
                message,
                chatOptions
        )).getResult().getOutput().getContent();
    }
}
